//
//  HYHome.m
//  child
//
//  Created by lijianguomac on 13-9-18.
//  Copyright (c) 2013年 lijianguomac. All rights reserved.
//

#import "HYHome.h"
#import "HYHomeCell.h"
#import "HYCImagePickerDemo.h"
#import "HYGrowingUpFiles.h"
#import "UIImageView+WebCache.h"
#import "HYLogin.h"

@interface HYHome (){
    BOOL isLogin;
}

@end

@implementation HYHome

@synthesize homeCellNib;

-(void)dealloc{
    [super dealloc];
    [homeCellNib release];
}

-(UINib*)statusCellNib
{
    if (homeCellNib == nil)
    {
        [homeCellNib release];
        homeCellNib = [[HYHomeCell nib] retain];
    }
    return homeCellNib;
}
- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        [self myInit];
    }
    return self;
}

- (void)myInit{

    UIImageView *ivHead = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [ivHead setImageWithURL:[NSURL URLWithString:@"http://c.hiphotos.baidu.com/album/w%3D2048/sign=bfa8ac5a03087bf47dec50e9c6eb562c/6a63f6246b600c3325794dd91b4c510fd9f9a19b.jpg"]];
    UIBarButtonItem *btn3 = [[UIBarButtonItem alloc] initWithCustomView:ivHead];
    [ivHead release];
    UILabel *lblName = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 20)];
    [lblName setFont:[UIFont systemFontOfSize:11]];
    [lblName setTextColor:[UIColor whiteColor]];
    [lblName setText:@"金贝贝"];
    
    UILabel *lblNum = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, 100, 10)];
    [lblNum setFont:[UIFont systemFontOfSize:9]];
    [lblNum setTextColor:[UIColor whiteColor]];
    [lblNum setText:@"0522 8831"];
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    [view addSubview:lblName];
    [view addSubview:lblNum];
    [lblName release];
    [lblNum release];
    
    UIBarButtonItem *btn4 = [[UIBarButtonItem alloc] initWithCustomView:view];
    [view release];
    
    NSArray *leftButtonArray = [[NSArray alloc] initWithObjects:btn3,btn4, nil];
    
    self.navigationItem.leftBarButtonItems = leftButtonArray;
    [btn3 release];
    [btn4 release];
    [leftButtonArray release];
    
    UIButton *btnSetting = [UIButton buttonWithType:UIButtonTypeCustom];
    btnSetting.frame = CGRectMake(0, 0, 20, 20);
    [btnSetting setBackgroundImage:[UIImage imageNamed:@"header_setup_onclick"]  forState:UIControlStateNormal];
    UIBarButtonItem *btn1 = [[UIBarButtonItem alloc] initWithCustomView:btnSetting];
    
    UIButton *btnMessage = [UIButton buttonWithType:UIButtonTypeCustom];
    btnMessage.frame = CGRectMake(0, 0, 25, 20);
    [btnMessage setBackgroundImage:[UIImage imageNamed:@"header_message_onclick"]  forState:UIControlStateNormal];
    UIBarButtonItem *btn2 = [[UIBarButtonItem alloc] initWithCustomView:btnMessage];
    
    NSArray *buttonArray = [[NSArray alloc]
                            initWithObjects:btn1,btn2, nil];
    
    self.navigationItem.rightBarButtonItems = buttonArray;
    [btn1 release];
    [btn2 release];
    [buttonArray release];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
    if ( IOS7_OR_LATER )
    {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.modalPresentationCapturesStatusBarAppearance = NO;
        
    }
#endif
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
//    if(!isLogin){
//        HYLogin *login = [[HYLogin alloc] init];
//        [self presentModalViewController:login animated:YES];
////        [self.navigationController pushViewController:login animated:YES];
//        [login release];
//        isLogin = YES;
//    }
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   
    
    UINavigationController *nar = (UINavigationController *)[self.tabBarController.viewControllers objectAtIndex:0];
    
    return [Tool getValidViewHeight:self.tabBarController nar:nar];
}
- (id)cellForTableView:(UITableView *)tableView fromNib:(UINib *)nib {
    static NSString *cellID = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        NSArray *nibObjects = [nib instantiateWithOwner:nil options:nil];
        cell = [nibObjects objectAtIndex:0];
    }
    else {
        [(ETBaseCell *)cell reset];
    }
    
    return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HYHomeCell *homeCell = [self cellForTableView:tableView fromNib:self.statusCellNib];
    homeCell.delegate = self;
    homeCell.selectionStyle = UITableViewCellSelectionStyleNone;
    return homeCell;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     [detailViewController release];
     */
}

- (void)doGrowingUpFiles:(id)sender{
    
//    HYCImagePickerDemo *picker = [[HYCImagePickerDemo alloc] initWithNibName:@"HYCImagePickerDemo" bundle:nil];
//    [self.navigationController pushViewController:picker animated:YES];
////    [self.navigationController presentModalViewController:picker animated:YES];
//    [picker release];
    
    HYGrowingUpFiles *growingUpFiles = [[HYGrowingUpFiles alloc] initWithStyle:UITableViewStylePlain];
    growingUpFiles.title = @"成长档案";
    [self.navigationController pushViewController:growingUpFiles animated:YES];
    [growingUpFiles release];
    
    
}

@end
